<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: a
  Date: 2024/3/22
  Time: 8:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>

<html>
<head>
    <script>function Message() {
        window.location.href = 'MessageServlet';
    }

    function exitLogin() {
        window.location.href = 'UserServlet?action=logout';
    }

    function redirectToLogin() {
        window.location.href = 'Login.jsp';
    }

    function redirectToInformation() {
        window.location.href = 'Information.jsp';
    }
    </script>
</head>
<title>首</title>
<body>
<h1 style="text-align: center;color: saddlebrown"><i>首</i></h1>
<p style="text-align: center">
    <c:set var="name" value="${sessionScope.username}" scope="application"/>
    <c:set var="visitors" value="${applicationScope.visitors}" scope="application"/>
</p>

<%--<c:if test="${not empty sessionScope.username}">--%>
<%--<h3 style="text-align: center">欢迎 ${username} 先生!</h3>--%>
<%--</c:if>--%>
<%--<c:if test="${empty sessionScope.username}">--%>
<%--<h3 style="text-align: center">您尚未登录，请点击下方按钮登录。</h3>--%>
<%--</c:if>--%>
<%--似乎更推荐choose-when-otherwise的方式--%>
<c:choose>
    <c:when test="${not empty sessionScope.username}">
        <p style="text-align: center">
            您是高级会员制网站的第<c:out value="${visitors}" default="1"/>位访客
        </p>
        <h3 style="text-align: center">欢迎 ${username} 先生!</h3>
    </c:when>
    <c:otherwise>
        <h3 style="text-align: center">您尚未登录，请点击下方按钮登录。</h3>
    </c:otherwise>
</c:choose>

<button onclick="redirectToLogin()">登录</button>
<button onclick="redirectToInformation()">信息</button>
<c:if test="${not empty sessionScope.username}">
    <button onclick="exitLogin()">退出登录</button>
    <br>
    <hr>
    <br>
    <button onclick="Message()">前往留言板</button>
</c:if>
</body>
</html>
